#include <bits/stdc++.h>
#define lson i<<1
#define rson i<<1|1
#define bug printf("Bug\n")
using namespace std;
const int N=3e5+50;
const int M=6e5+50;
int n,m,r,p,u,v,q,x,y,z;
struct Edge{
    int v,next;
}edge[M];
int cnt,head[N];
void init(){
    cnt=0;
    memset(head,-1,sizeof(head));
}
void addEdge(int u,int v){
    edge[cnt]=Edge{v,head[u]};
    head[u]=cnt++;
    edge[cnt]=Edge{u,head[v]};
    head[v]=cnt++;
}
//val:原始点权 fa:父节点 siz:子树大小 id:dfs序 dep:深度 top:所在链 son:重儿子
int sz,val[N],fa[N],siz[N],son[N],id[N],dep[N],top[N],rk[N];
//预处理出fa siz dep son
void dfs1(int u,int f,int d){
    fa[u]=f;
    dep[u]=d;
    siz[u]=1;
    for(int i=head[u];i!=-1;i=edge[i].next){
        int v=edge[i].v;
        if(v==f){
            continue;
        }
        dfs1(v,u,d+1);
        siz[u]+=siz[v];
        if(siz[v]>siz[son[u]]){
            son[u]=v;
        }
    }
}
//处理出id top
void dfs2(int u,int t){
    id[u]=++sz;
    rk[sz]=u;
    top[u]=t;
    if(!son[u]){
        return;
    }
    dfs2(son[u],t);
    for(int i=head[u];i!=-1;i=edge[i].next){
        int v=edge[i].v;
        if(v!=fa[u] && v!=son[u]){
            dfs2(v,v);
        }
    }
}
struct node{
    int l,r,sum,tag;
}tree[N<<2];
//向上更新信息
void pushup(int i){
    tree[i].sum=(tree[lson].sum+tree[rson].sum)%p;
}
//向下更新信息，标记下传
void pushdown(int i){
    tree[lson].sum+=(tree[lson].r-tree[lson].l+1)*tree[i].tag;
    tree[lson].sum%=p;
    tree[rson].sum+=(tree[rson].r-tree[rson].l+1)*tree[i].tag;
    tree[rson].sum%=p;
    tree[lson].tag+=tree[i].tag;
    tree[rson].tag+=tree[i].tag;
    tree[i].tag=0;
}
void build(int i,int x,int y){
    tree[i].l=x;
    tree[i].r=y;
    if(x==y){
        tree[i].sum=val[rk[x]];
        return;
    }
    int mid=x+(y-x)/2;
    build(lson,x,mid);
    build(rson,mid+1,y);
    pushup(i);
}
//单点更新
void change(int i,int x,int y,bool add){
    int l=tree[i].l;
    int r=tree[i].r;
    int mid=(l+r)>>1;
    if(l==r){
        tree[i].sum=y%p;
        return;
    }
    if(x<=mid){
        change(lson,x,y,add);
    }else{
        change(rson,x,y,add);
    }
    pushup(i);
}
//区间求和
int querysum(int i,int x,int y){
    int l=tree[i].l;
    int r=tree[i].r;
    int mid=(l+r)>>1;
    if(x==l && r==y){
        return tree[i].sum%p;
    }
    if(tree[i].tag){
        pushdown(i);
    }
    if(y<=mid){
        return querysum(lson,x,y);
    }else if(x>mid){
        return querysum(rson,x,y);
    }else{
        return querysum(lson,x,mid)+querysum(rson,mid+1,y);
    }
}
//区间更新
void update(int i,int x,int y,int c,bool add){
    int l=tree[i].l;
    int r=tree[i].r;
    int mid=(l+r)>>1;
    if(l>y || r<x){
        return;
    }
    if(l>=x && r<=y){
        tree[i].sum=(tree[i].sum+(tree[i].r-tree[i].l+1)*c)%p;
        tree[i].tag+=c;
        return;
    }
    if(tree[i].tag){
        pushdown(i);
    }
    if(x<=mid){
        update(lson,x,y,c,add);
    }
    if(y>mid){
        update(rson,x,y,c,add);
    }
    pushup(i);
}
//路径权值修改
void updatePath(int x,int y,int z){
    z%=p;
    int t=0;
    while(top[x]!=top[y]){
        if(dep[top[x]]<dep[top[y]]){
            swap(x,y);
        }
        update(1,id[top[x]],id[x],z,true);
        x=fa[top[x]];
    }
    if(id[x]>id[y]){
        swap(x,y);
    }
    update(1,id[x],id[y],z,true);
    return;
}
//路径权值查询
int queryPathSum(int x,int y){
    int ans=0;
    while(top[x]!=top[y]){
        if(dep[top[x]]<dep[top[y]]){
            swap(x,y);
        }
        ans+=querysum(1,id[top[x]],id[x]);
        ans%=p;
        x=fa[top[x]];
    }
    if(id[x]>id[y]){
        swap(x,y);
    }
    ans+=querysum(1,id[x],id[y]);
    return ans%p;
}
//子树权值修改
void updateSon(int x,int z){
    update(1,id[x],id[x]+siz[x]-1,z%p,true);
}
//子树权值查询
int querySonSum(int x){
    return querysum(1,id[x],id[x]+siz[x]-1)%p;
}
int main(void){
    //freopen("data.txt","r",stdin);
    scanf("%d%d%d%d",&n,&m,&r,&p);
    for(int i=1;i<=n;i++){
        scanf("%d",&val[i]);
    }
    init();
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&u,&v);
        addEdge(u,v);
    }
    dfs1(r,0,1);
    dfs2(r,r);
    build(1,1,n);
    while(m--){
        scanf("%d",&q);
        if(q==1){
            scanf("%d%d%d",&x,&y,&z);
            updatePath(x,y,z);
        }else if(q==2){
            scanf("%d%d",&x,&y);
            printf("%d\n",queryPathSum(x,y)%p);
        }else if(q==3){
            scanf("%d%d",&x,&z);
            updateSon(x,z);
            // printf("n %d\n",n);
            // for(int i=1;i<=n;i++){
            //     printf("-- %d %d\n",id[i],val[i]);
            // }
        }else{
            scanf("%d",&x);
            printf("%d\n",querySonSum(x)%p);
        }
    }
    return 0;
}